package com.iran.singleton;

/**
 * SingletonEnum 推荐第一名
 * 内部SingleEnumIn的枚举在创建时，就会执行构造函数创建单例对象，并且唯一。并且不会出现指令重排
 * @author yilang
 * @date 2021/5/30 0030
 **/
public class SingletonEnum {

    private SingletonEnum(){

    }
    private enum Singleton{
        INSTANCE;

        private final SingletonEnum singletonEnum;
        Singleton(){
            singletonEnum = new SingletonEnum();
        }
        public SingletonEnum getSingletonEnum(){
            return singletonEnum;
        }
    }
    public static SingletonEnum getInstance(){
        return Singleton.INSTANCE.getSingletonEnum();
    }
}
